package cn.liontalk.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: 周哲
 * @package: cn.liontalk.config
 * @description:
 * @date: 2019/1/23 21:28
 * @version: V1.0
 */
@Configuration
public class RabbitmqConfig {

    public static final String PREFIX = "MIAOSHA";

    public static final String QUEUE = "queue";
    public static final String TOPIC_QUEUE1 = "topic_queue1";
    public static final String TOPIC_QUEUE2 = "topic_queue2";
    public static final String TOPIC_EXCHANGE = "topic_queue2";
    public static final String ROUTING_KEY1 = "topic.key1";

    /**
     * 表示一个单词。 #表示0个或者多个单词
     */
    public static final String ROUTING_KEY2 = "topic.#";


    public static final String EXCHANGE = PREFIX + "EXCHANGE";
    public static final String MIAOSHA_QUEUE = PREFIX + "QUEUE";
    public static final String ROUTINGKEY = PREFIX + "KEY";

    @Bean
    public Queue getQueue() {
        return new Queue(QUEUE, true);
    }


    @Bean
    public Queue topciQueueOne(){
        return new Queue(TOPIC_QUEUE1, true);
    }

    @Bean
    public Queue topciQueueTwo(){
        return new Queue(TOPIC_QUEUE2, true);
    }



    @Bean
    public Queue miaoShaQueue(){
        return new Queue(MIAOSHA_QUEUE, true);
    }

    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(TOPIC_EXCHANGE);
    }

    @Bean
    public TopicExchange miaoShaExchange(){
        return new TopicExchange(EXCHANGE);
    }

    @Bean
    public Binding getBingingOne(){
        return BindingBuilder.bind(topciQueueOne()).to(topicExchange()).with(ROUTING_KEY1);
    }

    @Bean
    public Binding getBiningTwo(){
        return BindingBuilder.bind(topciQueueTwo()).to(topicExchange()).with(ROUTING_KEY2);
    }


    @Bean
    public Binding getMiaoShaBinging(){
        return BindingBuilder.bind(miaoShaQueue()).to(miaoShaExchange()).with(ROUTINGKEY);
    }

}
